﻿using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.EntityFrameworkCore;
using FireBillBook.Core.Entities;

namespace FireBillBook.Core.Repos
{
    public class BillDbContext:DbContext
    {
        public BillDbContext(DbContextOptions contextOptions) : base(contextOptions)    
        {

        }

        protected override void OnModelCreating(ModelBuilder builder)
        {
            // 消费记录
            builder.Entity<ConsumptionRecord>().HasKey(a => a.Id);

            // 交易平台
            builder.Entity<TradingPlatform>().HasKey(a => a.Name);

            // 交易账号
            builder.Entity<TradingAccount>().HasKey(a => a.Id);

            // 交易类型
            builder.Entity<ConsumptionType>().HasKey(a => a.Id);

            // 账单原始记录
            // 联合主键
            builder.Entity<BillingSourceData>().HasKey(a => a.DataId);

        }

        public DbSet<ConsumptionRecord> ConsumptionRecords { get; set; }
        public DbSet<ConsumptionType> ConsumptionTypes { get; set; }
        public DbSet<TradingPlatform> TradingPlatforms { get; set; }
        public DbSet<TradingAccount> TradingAccounts { get; set; }

        public DbSet<BillingSourceData> BillingSourceDatas { get; set; }
    }
}
